<template>
  <div class="w100 h100">
    <list-table-new v-bind="tableSetting" ref="klTable"></list-table-new>
  </div>
</template>
<script>
import { queryOnDutyRecordList } from "@/api/operationManagement/handoverManagement.js";
export default {
  data() {
    return {
      tableSetting: {
        selectionShow: false,
        pageConfig: {
          pageCode: "onDutyRecord",
          userId: this.$store.getters.userInfo.id,
        },
        searchObj: {
          searchMethod: (params, sortStr) => {
            this.getTableData(params, sortStr);
          },
          queryData: {
            page: 1,
            pageSize: 15,
          },
          searchArr: [
            {
              type: "organization",
              label: "值班单位",
              model: "deptName",
              idsStr: "deptId",
              placeholder: "请选择",
            },
            {
              type: "location",
              label: "值班地点",
              model: "locationName",
              idsStr: "locationId",
              placeholder: "请输入",
            },
            {
              type: "userOnly",
              label: "用户名",
              model: "userName",
              idsStr: "account",
              placeholder: "请输入",
            },
            {
              type: "daterange",
              label: "值班日期",
              model: "dutyDate",
              placeholder: "请选择",
            },
            {
              label: "值班人员类型",
              model: "dutyType",
              type: "select",
              option: this.$store.getters.dirtData("operation_duty_type"),
            },
          ],
        },
        //过滤器的值
        filterFormData: {},
        //过滤器的默认值
        defaultFilterData: {},
        userCustomData: [],
        actionList: [
          {
            name: "导出",
            icon: "el-icon-download",
            disabled: !this.$store.getters.isBtnAuth("export"), //控制按钮的禁用
            content: "未授权功能", //禁用提示内容
            method: (row) => {
              this.download();
            },
          },
        ],
        tableMethods: {
          //点击行的方法
          rowClick: (row) => {},
        },
        column: [
          {
            label: "用户名",
            prop: "userName",
            sortable: "custom",
          },
          {
            label: "值班单位",
            prop: "deptName",
            sortable: "custom",
          },
          {
            label: "值班地点",
            prop: "locationName",
            sortable: "custom",
          },
          {
            label: "值班班次",
            prop: "shiftName",
            sortable: "custom",
          },
          {
            label: "值班岗位",
            prop: "dutyType",
            sortable: "custom",
            formatter: (row) => {
              return this.$store.getters.fineDirtDataName(
                "operation_duty_type",
                row.dutyType
              );
            },
          },
          {
            label: "值班日期",
            prop: "dutyDate",
            sortable: "custom",
          },
          {
            label: "上班时间",
            prop: "openingTime",
          },
          {
            label: "下班时间",
            prop: "closingTime",
          },
          {
            label: "上班时长",
            prop: "workDurationStr",
          },
        ],
      },
      searchData: {},
    };
  },
  mounted() {
    this.$refs.klTable.getTableConfig();
    this.init();
  },
  methods: {
    init() {
      this.$refs.klTable.searchData();
    },
    //获取列表数据
    getTableData(params, sortStr) {
      let queryData = Object.assign({}, params);
      this.searchData = params;
      if (sortStr.length > 0) {
        queryData.orders = sortStr;
      }
      queryOnDutyRecordList(queryData).then((res) => {
        this.$set(this.tableSetting, "tableData", res.data.list);
        this.$set(this.tableSetting, "totalNumber", res.data.total);
      });
    },
    //导出
    download() {
      let paramStr = "";
      let params = this.searchData;
      for (const key in params) {
        if (Object.hasOwnProperty.call(params, key)) {
          if (params[key] && params[key] != "") {
            paramStr += `${key}=${params[key]}&`;
          }
        }
      }
      paramStr = paramStr.substring(0, paramStr.length - 1);
      let path = `eam-service-operation/duty/export?${paramStr}`;
      let fileName = `值班班记录`;
      this.$utils.downloadFile(null, fileName, path);
    },
  },
};
</script>
<style lang="less" scoped>
</style>